import { fileURLToPath, URL } from "node:url";

import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import vueDevTools from "vite-plugin-vue-devtools";

import { createHtmlPlugin } from "vite-plugin-html";

// https://vitejs.dev/config/
export default defineConfig({
  base: "./",
  plugins: [
    vue(),
    vueDevTools(),
    createHtmlPlugin({
      minify: true,
      inject: {
        data: {
          title: "cyue-share-console",
        },
      },
    }),
  ],
  resolve: {
    alias: {
      "@": fileURLToPath(new URL("./src", import.meta.url)),
    },
  },
  server: {
    proxy: {
      "/resource": {
        target: "https://localhost:4433/resource",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/resource/, ""),
        secure: false,
      },
      "/avatar": {
        target: "https://localhost:4433/avatar",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/avatar/, ""),
        secure: false,
      },
      "/api": {
        target: "https://localhost:4433/api",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ""),
        secure: false,
      },
    },
  },
});
